package com.wcr.school.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wcr.school.mapper.ClazzMapper;
import com.wcr.school.pojo.Clazz;
import com.wcr.school.pojo.Grade;
import com.wcr.school.service.ClazzService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Service("implClazzService")//当实现类多个时，通过@Service(“menuService1”)指定实现类
@Transactional
public class ImplClazzService  extends ServiceImpl<ClazzMapper, Clazz> implements ClazzService {
    @Override
    public List<Clazz> allClazzName() {
        //返回所有List集合返回
        return baseMapper.selectList(null);
    }

    @Override
    public IPage<Clazz> getClazzByOption(Page<Clazz> page, Clazz clazz) {
        QueryWrapper<Clazz> queryWrapper = new QueryWrapper<>();
        if(!StringUtils.isEmpty(clazz.getGradeName()))
            queryWrapper.like("grade_name",clazz.getGradeName());
        if(!StringUtils.isEmpty(clazz.getName()))
            queryWrapper.like("name",clazz.getName());
        queryWrapper.orderByAsc("id");
        Page page1 = baseMapper.selectPage(page,queryWrapper);
        return page1;
    }


}
